package com.hfzs.learnrabbitmq.service;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author: liuchenhui
 * @create: 2019-03-24 12:22
 **/
public class RabbitMQServer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("root");
        factory.setPassword("root123");
        factory.setVirtualHost("/");
        factory.setPort(5672);
        factory.setHost("127.0.0.1");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare("exchange.main", "fanout", true);
        channel.queueDeclare("test", true, false, false, null);
        channel.queueBind("test", "exchange.main", "rk.test");
        channel.basicPublish("exchange.main", "rk.test", null, "test".getBytes());
        channel.close();
        factory.clone();
    }
}
